﻿using Common.Core;
using Domain.Model.Entities;
using Domain.Model.Model;
using Domain.Model.ViewModel;
using Domain.Repository;
using Domain.Repository.Interface;
using Domain.Repository.Sugar;
using Domain.Services.Interface;
using SqlSugar;

namespace Domain.Services
{
    public class AreaService : BaseService<AreaEntities>, IAreaService
    {
        private readonly ISqlSugarClient db;
        private readonly IAreaRepository _area;
        public AreaService(IAreaRepository area) : base(area)
        {
            _area = area;
            db = SugarDao.GetInstance(Model.Enums.EnumDbType.MyDB);
        }
        /// <summary>
        /// 使用仓储基类获取，可以不构造直接使用
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public async Task<AreaModel> GetModel(string Id)
        {
            var model = await _area.QueryByIdAsync(Id);
            return model.MapTo<AreaModel, AreaEntities>();
        }
        /// <summary>
        /// 使用自定义仓储获取，需要构造
        /// </summary>
        /// <returns></returns>
        public async Task<List<AreaEntities>> SelDefineGetTop3List()
        {
            return await _area.SelDefineGetTop3List();
        }
        /// <summary>
        /// 不使用仓库方法，直接用单例dao操作
        /// </summary>
        /// <returns></returns>
        public async Task<List<AreaEntities>> SelfDefineGetList()
        {
            return await db.SqlQueryable<AreaEntities>("select top 5 * from Area").ToListAsync();
        }
    }
}